package com.situ.crm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.crm.entity.Role;
import com.situ.crm.service.IRoleService;
import com.situ.crm.vo.ResultDataVO;

@Controller
@RequestMapping(value = "/role")
public class RoleController {

	@Autowired
	private IRoleService roleService;

	// 打开角色管理页面
	@GetMapping(value = "/index")
	public String openUserPage() {
		return "role";
	}

	// 分页查询角色列表
	@GetMapping(value = "/list")
	@ResponseBody
	public ResultDataVO selectRoleList(String name, Integer page, Integer limit) {
		return roleService.selectRoleList(name, page, limit);
	}

	// 删除用户
	@PostMapping(value = "/del")
	@ResponseBody
	public void delRole(Integer id) {
		roleService.delRole(id);
	}

	// 保存用户
	@PostMapping(value = "/save")
	@ResponseBody
	public void saveRole(Role role) {
		roleService.save(role);
	}

	// 根据ID查询用户的数据
	@GetMapping(value = "/{id}")
	@ResponseBody
	public Role selectRoleById(@PathVariable("id") Integer id) {
		return roleService.selectRoleById(id);
	}

	// 查询所有的角色
	@GetMapping(value = "/all")
	@ResponseBody
	public List<Role> selectAllRole(Integer userId) {
		return roleService.selectAllRole(userId);
	}

	@PostMapping(value = "/saveMenu")
	@ResponseBody
	public void saveMenu(Integer roleId, @RequestParam("ids[]") Integer[] ids) {
		roleService.saveMenu(roleId, ids);
	}
}
